import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';

/// 导航栏数据模型
class NavigationItemModel {
  final String label;
  final String icon;
  final Widget widget;
  final String  hasPerm;

  NavigationItemModel({
    required this.label,
    required this.icon,
    required this.widget,
    required this.hasPerm,
  });
}

/// 导航栏
class BuildNavigation extends StatelessWidget {
  final int currentIndex;
  final List<NavigationItemModel> items;
  final Function(int) onTap;

  const BuildNavigation({
    Key? key,
    required this.currentIndex,
    required this.items,
    required this.onTap,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var ws = <Widget>[];
    for (var i = 0; i < items.length; i++) {
      var color = (i == currentIndex) ? Colors.blue : null;
      var item = items[i];
      ws.add(
        GestureDetector(
            behavior: HitTestBehavior.opaque,
            excludeFromSemantics: false,
            onTap: () {
              onTap(i);
            },
            child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceAround, // 居中
                mainAxisSize: MainAxisSize.max, // 最大
                children: <Widget>[
                  // 图标
                  SvgPicture.asset(
                    item.icon,
                    width: 23,
                    height: 23,
                    color: color,
                  ),
                  // 文字
                  Text(
                    item.label,
                    style: TextStyle(
                      fontSize: 13.0,
                      color: color,
                    ),
                  ),
                ])),
      );
    }
    return BottomAppBar(
      color: Colors.white,
      elevation: 0,
      child: ConstrainedBox(
          constraints: const BoxConstraints.tightFor(height: 56),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: ws,
          )),
    );
  }
}
